package app.itw.tison.web.controller;


import app.itw.tison.user.model.User;
import itw.app.tison.service.user.UserService;
import java.util.List;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户web
 */
@RestController
@RequestMapping("/api/v1/user/")
public class UserController {


  @Reference(version = "1.0.0", url = "dubbo://127.0.0.1:12345")
  private UserService userService;

  @GetMapping("/hello")
  public Object hello(String name) {
    return "你好啊！"+System.currentTimeMillis();
  }


  @GetMapping("/get")
  public Object getUser(String name) {
    User userByName = userService.getUserByName(name);
    if (userByName == null) {
      return "暂无该用户";
    }
    return userByName;
  }

  @GetMapping("/list")
  public Object getUserList() {
    List<User> userList = userService.getUserList();
    if (userList == null || userList.size() == 0) {
      return "暂无用户";
    }
    return userList;
  }

}
